package Three_ZhuChangShuang.service;

import Three_ZhuChangShuang.entity.Person;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @Author zhu
 * @Date 2021/3/24 15:48
 * @ClassNmae AdminService
 * @Description 管理员登录过后的功能
 */
public class AdminService {
    Scanner scanner = new Scanner(System.in);
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Person[] persons;

    public Person[] getPersons() {
        return persons;
    }

    public void setPersons(Person[] persons) {
        this.persons = persons;
    }

    /**
     * @Author zhu
     * @Description 管理员进行疫苗接种操作
     * @Date 2021/3/23
     * @return void
     */
    public void vaccination(){
        System.out.println("请选择你要接种的用户(输入对应用户的姓名)：");
        System.out.println("---------------------------------------------------------------------------");
        for (int i = 0; i < persons.length ; i++) {
            if (persons[i]!=null && persons[i].getSpecies()!=0){
                System.out.println("用户 "+(i+1)+" 姓名:"+persons[i].getName()
                        +"\t电话："+persons[i].getNumber()
                        +"\t预约日期:"+persons[i].getaTime()
                        +"\t预约疫苗种类:"+((persons[i].getSpecies()==1)?"灭活疫苗\t":"腺病毒疫苗")
                        +"\t接种状态："+((persons[i].getStatus()==0)?"未接种":"已接种"));
            }
        }
        System.out.println("---------------------------------------------------------------------------");
        String s = scanner.next();
        for (int i = 0; i < persons .length; i++) {
            if (persons[i]!=null){
                if (persons[i].getName().equals(s)){
                    Date date = new Date();
                    persons[i].setStatus(1);
                    try {
                        persons[i].setiTime(sdf.format(date)); //获取当前日期 年月日
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    System.out.println("用户"+persons[i].getName()+"接种成功！");
                    return;
                }
            }
        }

        System.out.println("用户不存在！");

    }

    /**
     * @Author zhu
     * @Description 管理员查看预约用户
     * @Date 2021/3/23
     * @return void
     */
    public void appointmentView(){
        System.out.println("预约用户信息(注：预约日期为空的用户为未预约)：");
        System.out.println("-----------------------------------------------------------------------------");
        System.out.println("用户名\t\t\t联系方式\t\t\t预约日期\t\t\t接种疫苗\t\t\t是否接种");
        for (int i = 0; i < persons.length; i++) {
            if (persons[i] != null){
                System.out.println(persons[i].getName()+"\t\t\t"
                        + persons[i].getNumber()+"\t\t\t\t"
                        + persons[i].getaTime()+"\t\t"
                        + ((persons[i].getSpecies()==1)?"灭活疫苗\t":"腺病毒疫苗")+"\t\t"
                        +"接种状态："+((persons[i].getStatus()==0)?"未接种":"已接种"));
            }
        }
        System.out.println("-----------------------------------------------------------------------------\n");
    }

    /**
     * @Author zhu
     * @Description 管理员查看已经接种的用户
     * @Date 2021/3/23
     * @return void
     */
    public void inoculationView(){
        System.out.println("已接种用户信息如下：");
        System.out.println("-----------------------------------------------------------------------------");
        System.out.println("用户名\t\t\t联系方式\t\t\t预约日期\t\t\t接种日期\t\t\t接种疫苗");
        for (int i = 0; i < persons.length; i++) {
            if (persons[i] != null){
                if (persons[i].getStatus()==1){
                    persons[i].show();
                }
            }
        }
        System.out.println("-----------------------------------------------------------------------------\n");
    }

}
